package br.furb.controllers;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.furb.jpa.dao.DAOFactory;
import br.furb.jpa.persistence.GenericPersistenceException;
import br.furb.models.Usuario;

@FacesConverter(forClass = Usuario.class)
public class EstadoConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		try {
			return DAOFactory.getInstance("web").createDAO(Usuario.class)
					.findByPK(Integer.valueOf(value));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (GenericPersistenceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object objeto) {
		return objeto.toString();
	}

}
